package cn.com.fuhuitong.main.order.mode

import cn.com.fuhuitong.http.BaseAbstractManager
import cn.com.fuhuitong.http.BaseResponse
import cn.com.fuhuitong.http.ResponseSubscribeListener
import cn.com.fuhuitong.http.SubscribeListener
import cn.com.fuhuitong.main.host.mode.MainApi
import cn.com.fuhuitong.main.mine.entity.AddressDefaultResponse
import cn.com.fuhuitong.main.order.entity.*
import io.reactivex.Observable
import io.reactivex.disposables.Disposable
import retrofit2.http.Query

class OrderManager : BaseAbstractManager<OrderApi>(OrderApi::class.java) {


    /**
     *订单待提交页
     * */
    fun confirmOrder(
        token: String, entity: SubmitConfirmEntity,
        listener: SubscribeListener<SubmitGoodsResponse>
    ): Disposable {
        val confirmOrder: Observable<SubmitGoodsResponse> =
            apiService.confirmOrder(token, entity)
        return subscribe(confirmOrder, ResponseSubscribeListener(listener))
    }

    /**
     *获取抵扣积分
     * */
    fun useScore(
        token: String, listener: SubscribeListener<SubmitNatureResponse>
    ): Disposable {
        val confirmOrder: Observable<SubmitNatureResponse> =
            apiService.useScore(token)
        return subscribe(confirmOrder, ResponseSubscribeListener(listener))
    }

    /**
     *订单待提
     * */
    fun submitOrder(
        token: String,  entity: SubmitConfirmEntity,
        listener: SubscribeListener<SubmitOrderIdResponse>
    ): Disposable {
        val submitOrder: Observable<SubmitOrderIdResponse> =
            apiService.submitOrder(token,entity)
        return subscribe(submitOrder, ResponseSubscribeListener(listener))
    }


    /**
     *订单支付页
     * */
    fun orderPay(
        token: String, orderId: String,
        listener: SubscribeListener<PayResponse>
    ): Disposable {
        val orderPay: Observable<PayResponse> =
            apiService.orderPay(token, orderId)
        return subscribe(orderPay, ResponseSubscribeListener(listener))
    }

    /**
     * 获取订单列表
     * */
    fun orderList(
        token: String, page: String, limit: String, type: String,
        listener: SubscribeListener<OrderListResponse>
    ): Disposable {
        val orderList: Observable<OrderListResponse> =
            apiService.orderList(token, page, limit, type)
        return subscribe(orderList, ResponseSubscribeListener(listener))
    }


    /**
     *订单详情
     * */
    fun orderDetail(
        token: String, orderId: String,
        listener: SubscribeListener<OrderDetailsResponse>
    ): Disposable {
        val orderPay: Observable<OrderDetailsResponse> =
            apiService.orderDetail(token, orderId)
        return subscribe(orderPay, ResponseSubscribeListener(listener))
    }


    /**
     *订单取消
     * */
    fun orderCancel(
        token: String, orderId: String,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val orderCancel: Observable<BaseResponse> =
            apiService.orderCancel(token, orderId)
        return subscribe(orderCancel, ResponseSubscribeListener(listener))
    }


    /**
     *订单确认收货
     * */
    fun orderConfirm(
        token: String, orderId: String,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val orderConfirm: Observable<BaseResponse> =
            apiService.orderConfirm(token, orderId)
        return subscribe(orderConfirm, ResponseSubscribeListener(listener))
    }

}